<?php
class AController extends JYController {
	public $unid;
	public $username;
	
	public function __construct($controllerName, $actionName) {
		parent::__construct ( $controllerName, $actionName );
		/* 权限验证通过 */
		$this->checkUser();
		$this->unid = CSM_UNIT_ID;
		$this->username = CSM_USER_NAME;
	}
	
	private function checkUser() {
		/** 权限验证通过 */
		if((empty($_REQUEST['a']) && empty($_REQUEST['c'])) || $_REQUEST['a']=='login'){
			
		}else{
			if(!isset($_SESSION['user']) && empty($_SESSION['user']['username'])){
				//$this->alert('请登录后再查看.',"/");
				echo "<script>alert('请登录后再查看');parent.location.href='/'; </script>";
				exit();
			}
		}
		// 在此处设置全局用户信息
		define('CSM_USER_ID', $_SESSION['user']['user_id']?$_SESSION['user']['user_id']:0);
		define('CSM_USER_NAME', $_SESSION['user']['username']?$_SESSION['user']['username']:0);
		define('CSM_UNIT_ID',$_SESSION['user']['unit_id']?$_SESSION['user']['unit_id']:0);

		if (!isset($_SESSION['monthaccess'])) {
			$_SESSION['monthaccess'] = JYVisit::getTodayVisit(CSM_USER_ID);
			$_SESSION['dayaccess'] = JYVisit::getMonthVisit(CSM_USER_ID);
		}
	}
}